/* $Id$ */

#include HEADER (anima,thread.hh)
#include HEADER (anima,space.hh)
#include HEADER (anima,mm.hh)

START_NAMESPACE (anima)

thread_t *
thread_t::create (space_t *space)
{
  thread_t *thread = (thread_t *) mm::map (mm::CT_THREAD);

  if (!thread)
    return NULL;

  new (thread) thread_t ();

  if (!thread->init_instance (space))
    {
      mm::unmap ((u64_t) thread);
      return NULL;
    }

  thread->space = space;
  space->add (thread);

  mm::activate (thread);

  return thread;
}

END_NAMESPACE

